package com.sunxueqi.project.log.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sunxueqi.framework.web.controller.BaseController;
import com.sunxueqi.framework.web.vo.ResponseData;
import com.sunxueqi.project.log.service.IOperationLogService;
import com.sunxueqi.project.log.vo.OperationLog;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;

@Api(tags="操作日志")
@RestController
@RequestMapping("/log/operationLog")
public class OperationLogController extends BaseController{
	@Autowired
	private IOperationLogService operationLogService;
	
	/**
	 * 获取操作日志列表
	 * @param operationLog
	 * @return
	 */
	@GetMapping("/list")
	public ResponseData list(OperationLog operationLog) {
		startPage();
		List<OperationLog> list = operationLogService.selectOperationLogList(operationLog);
		return ResponseData.successTableData(list);
	}
	
	/**
	 * 删除操作日志
	 * @param ids
	 * @return
	 */
	@DeleteMapping("/{ids}")
	public ResponseData delete(@PathVariable String ids) {
		String [] idArray = StrUtil.split(ids, ",");
		return super.getResponseDataRow(operationLogService.deleteOperationLogByIds(idArray));
	}
	
	/**
	 * 清除所有登录日志
	 * @return
	 */
	@DeleteMapping("/clean")
	public ResponseData cleanLog() {
		operationLogService.cleanLog();
		return ResponseData.success();
	}
}
